

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>设备维护计划</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
  <link rel="stylesheet" href="../../layuiadmin/layui/css/layui.css" media="all">
  <link rel="stylesheet" href="../../layuiadmin/style/admin.css" media="all">
</head>
<body>
  <div class="layui-fluid">   
    <div class="layui-card-header plan-title">设备检修记录</div>
    <div class="layui-card">
      <div class="layui-card-body">
          <div style="padding-bottom: 10px">
                <div class="layui-form layui-card-header layuiadmin-card-header-auto">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">专业:</label>
                            <div class="layui-input-block">
                                <select name="major" id="majorList" lay-filter="majorListFilter">
                                    <option value="">请选择</option>
                                </select>
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">系统名:</label>
                            <div class="layui-input-block">
                                <select name="system" id="systemList" lay-filter='systemListFilter'>
                                    <option value="">请选择</option>
                                </select>
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">设备类型:</label>
                            <div class="layui-input-block">
                                <select name="equipment" id="equipmentList" lay-filter="equipmentList">
                                    <option value="">请选择</option>
                                </select>
                            </div>
                        </div>
                        <div class="layui-inline">
                            <button class="layui-btn layuiadmin-btn-admin" lay-submit lay-filter="LAY-user-back-search" id="searchBtn">
                                <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                            </button>
                        </div>
                        <div class="layui-inline" style="float:right">
                            <button class="layui-btn layuiadmin-btn-admin" data-type="add">添加</button>
                        </div>
                    </div>
                </div>
          </div>
        <table id="LAY-equipment-plan" lay-filter="LAY-equipment-plan"></table>   
        <script type="text/html" id="forMaintenanceFlag">
            {{#  if(d.maintenanceFlag == '1'){d.maintenanceFlag = '计划维修'}}
            {{d.maintenanceFlag}}
            {{#  } }}
        </script>
        <script type="text/html" id="forTaskStatus">
            {{#  if(d.taskStatus == '1'){d.taskStatus = '已处理'}}
            {{d.taskStatus}}
            {{#  } else {d.taskStatus = '未处理' }}
            {{d.taskStatus}}
            {{#  } }}
        </script>
        <script type="text/html" id="planOperate">
            <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="edit">查看详情</a>
            <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
        </script>
      </div>
    </div>
  </div>

 <script src="../../layuiadmin/layui/layui.js"></script>
  <script src='../../layuiadmin/modules/jTools.js'></script>
  <script>
  layui.config({
    base: '../../layuiadmin/' //静态资源所在路径
  }).extend({
    index: 'lib/index' //主入口模块
    , my_send: '../myModules/my_send'
  }).use(['index', 'equipment', 'table','my_send'], function(){
      var $ = layui.$
      ,form = layui.form
      ,table = layui.table
      , my_send = layui.my_send
      , http_proxy = layui.http_proxy;
      $.ajax({
            url:http_proxy('/dev/maintenance/treeData'),
            async: false,
            dataType:'json',
            type:'get',
            success:function(data){
                $.each(data.data,function(index,item){
                    itemKey = item.key;
                    if(item.level == 0){
                        $('#majorList').append(new Option(item.value,item.key));
                    }
                })
                form.render('select');
            }
        });
        form.on('select(majorListFilter)', function(data){
            var dataKey = data.value;
            $.ajax({
                url:http_proxy('/dev/maintenance/treeData'),
                async: false,
                dataType:'json',
                type:'get',
                success:function(data){
                    $("#systemList").empty();
                    $("#systemList").append(new Option("请选择",""));
                    $.each(data.data,function(index1,item1){
                        if(item1.level == 1 && dataKey == item1.pid){
                            $('#systemList').append(new Option(item1.value,item1.key));
                        }
                    });
                    form.render('select');
                }
            });
        });
        form.on('select(systemListFilter)', function(data){
            var dataKey = data.value;
            $.ajax({
                url:http_proxy('/dev/maintenance/treeData'),
                async: false,
                dataType:'json',
                type:'get',
                success:function(data){
                    $("#equipmentList").empty();
                    $("#equipmentList").append(new Option("请选择",""));
                    $.each(data.data,function(index2,item2){
                        if(item2.level == 2 && dataKey == item2.pid){
                            $('#equipmentList').append(new Option(item2.value,item2.key));
                        }
                    });
                    form.render('select');
                }
            });
        });
     //点击查询按钮，重载表格
     form.on('submit(LAY-user-back-search)', function (data) {
       debugger
        //执行重载
        table.reload('planTableAll', {
            where: data.field
        });
    });
  
    //事件
    var active = {
      batchdel: function(){
        var checkStatus = table.checkStatus('LAY-user-back-manage')
        ,checkData = checkStatus.data; //得到选中的数据

        if(checkData.length === 0){
          return layer.msg('请选择数据');
        }
        
        layer.prompt({
          formType: 1
          ,title: '敏感操作，请验证口令'
        }, function(value, index){
          layer.close(index);
          
          layer.confirm('确定删除吗？', function(index) {
            
            //执行 Ajax 后重载
            /*
            admin.req({
              url: 'xxx'
              //,……
            });
            */
            table.reload('LAY-user-back-manage');
            layer.msg('已删除');
          });
        }); 
      }
      ,add: function(){
        layer.open({
          type: 2
          ,title: ''
          ,content: 'plan-addForm.html'
          ,area: ['80%', '80%']
          ,btn: ['确定', '取消']
          ,yes: function(index, layero){
            var iframeWindow = window['layui-layer-iframe'+ index]
            ,submitID = 'LAY-user-back-submit'
            ,submit = layero.find('iframe').contents().find('#'+ submitID);

            //监听提交
            iframeWindow.layui.form.on('submit('+ submitID +')', function(data){
              var field = data.field; //获取提交的字段
              
              //提交 Ajax 成功后，静态更新表格中的数据
              //$.ajax({});
              my_send({
                url: '/privilege/addPrivilege'
                , type: 'post'
                , data: field
                , success: function (obj) {
                table.reload('permissionTable');
                }
            })
            //   table.reload('LAY-user-front-submit'); //数据刷新
              layer.close(index); //关闭弹层
            });  
            
            submit.trigger('click');
          }
        }); 
      }
    }  
    $('.layui-btn.layuiadmin-btn-admin').on('click', function(){
      var type = $(this).data('type');
      active[type] ? active[type].call(this) : '';
    });
  });
  </script>
</body>
</html>
